Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exponential growth of plugin registry in App.init() #84

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

sjinks
Copy link
Member

@sjinks sjinks commented Sep 10, 2024

In Lando, Application.init() walks through the plugin registry (app.plugins.registry which is a reference to lando.plugins.registry) and invokes Plugin.load() on every plugin that has an app.js file.

The side effect of the Plugin.load() is that it adds every plugin passed to it to the registry. The net effect of this is the growth of the registry: the same plugin may be added several times.

Calls to Lando.getApp() and App.init() for a different application will double the size of the registry. Because the same plugin will be initialized twice, it will add the same event handlers twice to the application object. This eventually leads to memory leaks and the MaxListenersExceededWarning warning.

See: Automattic/vip-cli#2027

@sjinks sjinks self-assigned this Sep 10, 2024
this.registry.push(plugin);
this.log.debug('plugin %s loaded from %s', plugin.name, file);
this.log.silly('plugin %s has', plugin.name, plugin.data);
if (!this.registry.find(p => p.name === plugin.name)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be further optimized so that we don't do this O(n) find but I guess it's good enough :)

@sjinks sjinks merged commit 4d8465e into main Sep 10, 2024
58 checks passed
@sjinks sjinks deleted the fix-exponential-growth branch September 10, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants